<template>
	<uni-collapse accordion="true">
		<uni-collapse-item title="已委托房源">
			<view style="padding: 30rpx;">
				<uni-list v-for="(i,index) in passhouse" :key="index">
					<uni-list-item  :title="i.houseDetailaddress"  ></uni-list-item>
				</uni-list>
			</view>
		</uni-collapse-item>	
		<uni-collapse-item title="未委托房源">
			<view style="padding: 30rpx;">
				<uni-list v-for="(j,index1) in nopasshouse" :key="index1">
					<uni-list-item v-if="j.sellOrRent != 2" :title="j.houseDetailaddress" link :to="'/pages/agent/agentSelect?sellOrRent='+j.sellOrRent+'&houseId='+j.houseId"></uni-list-item>
				</uni-list>
			</view>
		</uni-collapse-item>
		</uni-collapse>
</template>
	 
<script>
import {mapState} from 'vuex';
	export default {
		data(){
			return{
				userId: 1,
				passhouse:[],
				nopasshouse:[],
			}
		},
		methods:{
			getHouseByUserId(){
				this.$axios.post('getHousesByUserId' ,this.qs.stringify({
					userId: this.user.userId
				}))
				.then(res => {
					this.house = res.data.Houses
					this.getselectAgentHouses()
				})
			},
			getAgentRenting(){
				this.$axios.post('getAgentRenting')
				.then(res => {
					this.rentingpasshouse = res.data.agentRentings
					this.rentingnopasshouse = res.data.noagentRentings
					for(let j=0 ; j < this.house.length ; j++){
						for(let k=0 ; k < this.rentingpasshouse.length ; k++){
							if(this.house[j].houseId  == this.rentingpasshouse[k].houseId){
								let temporary = {}
								temporary.houseId = this.house[j].houseId
								temporary.houseDetailaddress = this.house[j].houseDetailaddress
								temporary.type = 2
								this.passhosue.push(temporary)
							}
						}
					}
					for(let j=0 ; j < this.house.length ; j++){
						for(let k=0 ; k < this.rentingnopasshouse.length ; k++){
							if(this.house[j].houseId  == this.rentingnopasshouse[k].houseId){
								let temporary = {}
								temporary.houseId = this.house[j].houseId
								temporary.houseDetailaddress = this.house[j].houseDetailaddress
								temporary.type = 2
								this.nopasshouse.push(temporary)
							}
						}
					}
					this.getAgentSell()
				})
			},
			getAgentSell(){
				this.$axios.post('getAgentSell')
				.then(res => {
					this.sellpasshouse = res.data.agentSells
					this.sellnopasshouse = res.data.noagentSells
					for(let j=0 ; j < this.house.length ; j++){
						for(let k=0 ; k < this.sellpasshouse.length ; k++){
							if(this.house[j].houseId  == this.sellpasshouse[k].houseId){
								let temporary = {}
								temporary.houseId = this.house[j].houseId
								temporary.houseDetailaddress = this.house[j].houseDetailaddress
								temporary.type = 1
								this.passhosue.push(temporary)
							}
						}
					}
					for(let j=0 ; j < this.house.length ; j++){
						for(let k=0 ; k < this.sellnopasshouse.length ; k++){
							if(this.house[j].houseId  == this.sellnopasshouse[k].houseId){
								let temporary = {}
								temporary.houseId = this.house[j].houseId
								temporary.houseDetailaddress = this.house[j].houseDetailaddress
								temporary.type = 1
								this.nopasshouse.push(temporary)
							}
						}
					}
					this.forceUpdate()
				})
			},	
			getAgentHouses(){
				this.$axios.post('selectAgentHouses' ,this.qs.stringify({
									userId: this.user.userId
								}))
				.then(res => {
					this.passhouse = res.data.passhouse
					this.nopasshouse = res.data.nopasshouse
				})
			}
		},
		onLoad(){
			this.getAgentHouses()
		},
		computed: {
			...mapState(['user'])
		}
	}
</script>

<style>

</style>
	